package com.lagou.cl.util;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
 * @author 程  林
 * @date 2020-05-24 18:22
 * @description //
 * @since V1.0.0
 */
@Component
public class SpringBeanUtil implements ApplicationContextAware {

	private ApplicationContext applicationContext;

	@Override
	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
		this.applicationContext = applicationContext;
	}


	public <T> T getBeanByType(Class<T> tClass) {
		return this.applicationContext.getBean(tClass);
	}
}
